<?php
include '../dbconnect.php';
// 获取服务id
$service_id = isset($_GET['gid']) ? $_GET['gid'] : '';
if (empty($service_id)) {
    echo "服务ID不能为空！";
    exit;
}

// 使用预处理语句查询服务信息
$sql = "SELECT * FROM services WHERE SERVICE_ID = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $service_id);
$stmt->execute();
$result = $stmt->get_result();

if ($result->num_rows > 0) {
    $row = $result->fetch_assoc();
} else {
    echo "服务不存在！";
    exit;
}
?>

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../../favicon.ico">

    <title>服务编辑</title>

    <!-- Bootstrap core CSS -->
    <link href="./css/bootstrap.min.css" rel="stylesheet">

    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <!-- <link href="../../assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet"> -->

    <!-- Custom styles for this template -->
    <link href="./css/navbar-fixed-top.css" rel="stylesheet">

    <!-- Just for debugging purposes. Don t actually copy these 2 lines! -->
    <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
    <!-- <script src="../../assets/js/ie-emulation-modes-warning.js"></script> -->

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>

<!-- Fixed navbar -->
<?php include 'adminHeader.php'; ?>

<div class="container">
    <br><br><br><br>
    <table class="table table-striped">
        <thead>
            <tr>
                <th colspan="2">edit service</th>
            </tr>
        </thead>
        <tbody>
            <form class="" action="doeditServices.php?gid=<?php echo $service_id ?>" method="post" enctype="multipart/form-data">
                <tr>
                    <td>SERVICE_NAME</td>
                    <td><input type="text" name="SERVICE_NAME" value="<?php echo htmlspecialchars($row['SERVICE_NAME']); ?>"></td>
                </tr>
                <tr>
                    <td>SERVICE_TYPE</td>
                    <td><input type="text" name="SERVICE_TYPE" value="<?php echo htmlspecialchars($row['SERVICE_TYPE']); ?>"></td>
                </tr>
                <tr>
                    <td>SERVICE_CONTENT</td>
                    <td><input type="text" name="SERVICE_CONTENT" value="<?php echo htmlspecialchars($row['SERVICE_CONTENT']); ?>"></td>
                </tr>
                <tr>
                    <td>SERVICE_PICTURE</td>
                    <td>
                        <input type="file" name="SERVICE_PICTURE" accept="image/*">
                        <br>
                        <img src="<?php echo htmlspecialchars($row['SERVICE_PICTURE']); ?>" alt="Current Picture" style="max-width: 100px;">
                    </td>
					<input type="hidden" name="SERVICE_PICTURE" value="<?php echo htmlspecialchars($row['SERVICE_PICTURE']); ?>" >
                </tr>
                <tr>
                    <td></td>
                    <td><input type="submit" class="btn btn-info" name="" value="更新"></td>
                </tr>
            </form>
        </tbody>
    </table>
</div> <!-- /container -->

<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="../../assets/js/vendor/jquery.min.js"><\/script>')</script>
<script src="./js/bootstrap.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<!-- <script src="../../assets/js/ie10-viewport-bug-workaround.js"></script> -->
</body>
</html>